package client.comm.baoding.adapter.page

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import client.comm.baoding.R
import client.comm.baoding.fragment.*
import client.comm.commlib.ContextProvider

class Zcjl2FragmentPageAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {

    val fragments: Array<Fragment?> by lazy {
        arrayOfNulls(3)
    }

    override fun getItem(position: Int): Fragment {
        if (position == 0 && fragments[0] == null) {
            fragments[0] = Zcjl2OneFragment()
        } else if (position == 1 && fragments[1] == null) {
            fragments[1] = Zcjl2TwoFragment()
        } else if (position == 2 && fragments[2] == null) {
            fragments[2] = Zcjl2ThreeFragment()
        }
        return fragments[position]!!
    }

    override fun getCount(): Int {
        return fragments.size
    }

    override fun getPageTitle(position: Int): CharSequence? {
        var titleId = 0
        if (position == 0 && fragments[0] == null) {
            titleId = R.string.zc_dsf
        } else if (position == 1 && fragments[1] == null) {
            titleId = R.string.zc_kjy
        } else if (position == 2 && fragments[2] == null) {
            titleId = R.string.zc_tjq
        }
        return ContextProvider.get().activity?.getString(titleId)!!
    }

}